Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Collapse DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Expand v.IMP Queriesv.IMP Queries
Expand XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

Trigger Database

 
      USE myDB
      GO

      IF EXISTS(
          SELECT  *
          FROM    sys.triggers
          WHERE   name = N'table_alter_drop_safety'
          AND     parent_class_desc = N'DATABASE'
      )
      DROP TRIGGER table_alter_drop_safety ON DATABASE
      GO

      CREATE TRIGGER table_alter_drop_safety ON DATABASE
          FOR DROP_TABLE, ALTER_TABLE
      AS
          IF IS_MEMBER ('db_owner') = 0
      BEGIN
          PRINT 'You must ask your DBA to drop or alter tables!'
          ROLLBACK TRANSACTION
      END
      GO